package controller

import (
	"gin/response"
	"gin/service"
	"gin/types"
	"github.com/gin-gonic/gin"
)

type Entity struct {
}

var (
	entityService service.Entity
)

func (c *Entity) GetEntityRelationInfo(ctx *gin.Context) {
	var req types.GetEntityRelationInfoReq
	err := ctx.ShouldBindJSON(&req)
	tenantUserId := service.GetInt64FromContext(ctx, "tenant_id")

	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}

	var resData interface{}
	resData, queryErr := entityService.GetEntityRelationInfo(req.Id, req.Type, tenantUserId, req.Page, req.InitialEpisodeCode, req.ShowingsNumber)
	if queryErr != nil {
		// 查询失败
		response.Fail(ctx, nil, queryErr.Error())
	} else {
		// 查询成功
		response.Success(ctx, gin.H{"data": resData}, "success")
	}
}

// 获取资产关联镜头统计
func (c *Entity) GetAssetRelationShotCount(ctx *gin.Context) {
	var req types.GetAssetRelationShotCountReq
	err := ctx.ShouldBindJSON(&req)
	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}

	var resData interface{}
	resData, queryErr := entityService.GetAssetRelationShotCount(req.GetAssetRelationShotCountParam.ProjectId, req.GetAssetRelationShotCountParam.ProjectId, req.GetAssetRelationShotCountParam.Page)
	if queryErr != nil {
		// 查询失败
		response.Fail(ctx, nil, queryErr.Error())
	} else {
		// 查询成功
		response.Success(ctx, gin.H{"data": resData}, "success")
	}
}

// 获取资产关联的镜头ids
func (c *Entity) GetAssetRelationShotIds(ctx *gin.Context) {
	var req types.GetAssetRelationShotIdsReq
	err := ctx.ShouldBindJSON(&req)
	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}

	var resData interface{}
	resData, queryErr := entityService.GetAssetRelationShotIds(req.EntityId, req.InitialEpisodeCode, req.ProjectId)
	if queryErr != nil {
		// 查询失败
		response.Fail(ctx, nil, queryErr.Error())
	} else {
		// 查询成功
		response.Success(ctx, gin.H{"data": resData}, "success")
	}
}

// GetAssetRelationShotList 获取资产关联的镜头列表
func (c *Entity) GetAssetRelationShotList(ctx *gin.Context) {
	var req types.GetAssetRelationShotListReq
	err := ctx.ShouldBindJSON(&req)
	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}

	var resData interface{}
	resData, queryErr := entityService.GetAssetRelationShotList(req.Param.EntityId, req.Param.InitialEpisodeCode)
	if queryErr != nil {
		// 查询失败
		response.Fail(ctx, nil, queryErr.Error())
	} else {
		// 查询成功
		response.Success(ctx, gin.H{"data": resData}, "success")
	}
}

//GetMultipleEntityRelationIds 获取多个实体的关联ids
func (c *Entity) GetMultipleEntityRelationIds(ctx *gin.Context) {
	var req types.GetMultipleEntityRelationIdsReq
	err := ctx.ShouldBindJSON(&req)
	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}

	var resData interface{}
	resData, queryErr := entityService.GetMultipleEntityRelationIds(req.EntityIds)
	if queryErr != nil {
		// 查询失败
		response.Fail(ctx, nil, queryErr.Error())
	} else {
		// 查询成功
		response.Success(ctx, gin.H{"data": resData}, "success")
	}
}

//GetMultipleEntityRelationCount 获取关联的统计
func (c *Entity) GetMultipleEntityRelationCount(ctx *gin.Context) {
	var req types.GetMultipleEntityRelationCountReq
	err := ctx.ShouldBindJSON(&req)
	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}

	var resData interface{}
	resData, queryErr := entityService.GetMultipleEntityRelationCount(req)
	if queryErr != nil {
		// 查询失败
		response.Fail(ctx, nil, queryErr.Error())
	} else {
		// 查询成功
		response.Success(ctx, gin.H{"data": resData}, "success")
	}
}

// GetAssetRelationShotTaskCardList 获取资产任务卡片关联的镜头列表
func (c *Entity) GetAssetRelationShotTaskCardList(ctx *gin.Context) {

	var req types.GetAssetRelationShotTaskCardListReq
	err := ctx.ShouldBindJSON(&req)
	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}

	var resData interface{}
	resData, queryErr := entityService.GetAssetRelationShotTaskCardList(req.Param.EntityId)
	if queryErr != nil {
		// 查询失败
		response.Fail(ctx, nil, queryErr.Error())
	} else {
		// 查询成功
		response.Success(ctx, gin.H{"data": resData}, "success")
	}
}
